package com.skymxc.wandroidtodo.data.net;

import androidx.annotation.NonNull;

import com.skymxc.wandroidtodo.entity.NetResponse;
import com.skymxc.wandroidtodo.entity.NetResponseException;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;


/**
 * <p>
 *
 * </p>
 *
 * @author 孟祥超
 * <p>
 * date: 2021/12/1  7:35 上午
 */
class NetResponseFunction<T> implements Function<NetResponse<T>, ObservableSource<T>> {
    @Override
    public ObservableSource<T> apply(@NonNull NetResponse<T> tNetResponse) throws Exception {
        if (tNetResponse.errorCode!=0){
            return Observable.error(new NetResponseException(tNetResponse.errorCode,tNetResponse.errorMsg));
        }
        //-1001 去登陆
        return Observable.just(tNetResponse.data);
    }
}
